<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/style/dtree/dtree.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/js/layuiadmin-1.2.1/style/dtree/font/dtreefont.css}" media="all">
    <th:block th:include="include :: header('区域数据列表')" />
    <style type="text/css">
        .west {width:310px;border-top: 15px solid #f2f2f2;}
        .layui-body {left:310px; border: 16px solid #F2f2f2; border-bottom: 0;padding: 0 16px}
        .layui-side-scroll{border-right: 1px solid #f6f6f6;width:310px;}
        .layui-logo{color: #fff;height: 41px;line-height: 41px;font-size: 16px}
        .layui-logo span{display: block;width: 277px;float: left;margin-left: 10px;}
        .layui-nav {background: #FFF;color:#000;width:310px;}
        .layui-col-sm4 {width: 23%;}
        .layui-btn-xs {height: 32px;line-height: 32px;padding: 0 16px;font-size: 12px;}
        .layui-icon-shrink-right:before {background-color:rgba(243,160,65,0.9)}
        .layui-icon-spread-left:before {background-color:rgba(243,160,65,0.9)}
	</style>
</head>
<body class="no-skin">
 <div class="main-container" id="main-container">
    <div class="main-content">
        <div class="west layui-side">
            <div class="layui-side-scroll">
                <div class="layui-logo" >
                    <span>地区列表</span>
                    <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
                        <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;float: right"></i>
                    </a>
                </div>
                <div class="layui-nav layui-nav-tree">
                    <div id="dhtree" class="demo-tree demo-tree-box"></div>
                </div>
            </div>
            <div class="panel layout-expand layui-expand-west" id="panel" style="display: none; width: 114px; left: 0px; top: 0px;height: 41px;color: #fff;">
                <div class="panel-header">
                    <div class="panel-tool"  id="panel-tool" style="text-align: center; width: 114px;height: 41px;line-height: 41px;font-size: 16px;">
                        <span class="panel-body panel-title" style="width: 114px;">地区列表</span>
                        <a href="javascript:;" class="menuBtn">
                            <i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;float: right"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-body" id="LAY_app_body">
            <div class="north">
                <div class="north-content">
                    <form>
                        <th:block th:include="listinclude :: searchTop" />
					</form>
                </div>
            </div>
            <div class="mid-content">
                <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
            </div>
        </div>
    </div>
 </div>
 <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs dhicon dh-edit" lay-event="edit">&nbsp;编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" lay-event="del">&nbsp;删除</a>
 </script>
 <script type="text/html" id="toolbar1">
    <div class="layui-btn-container">
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增本级</span></p>
        </div>
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addchildbtn">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增子级</span></p>
        </div>
    </div>
 </script>
 <th:block th:include="include :: footer" />
 <script th:src="@{/dhecp/js/left-tree.js?v=1}"></script>
 <script th:inline="javascript">
     /*<![CDATA[*/
     var vtype = [[${vtype}]];
     var k_fields =[[${fields}]];
     var moduleTable=[[${moduleTable}]];
     /*]]>*/
</script>
<script type="text/javascript">
    $(".layui-logo").css({"background":pellucidityTen,"text-align":"center"});
    $(".layui-expand-west").css({"background": pellucidityTen,position: "absolute"});
var pguid=0,wherestr={};
var vname = "无",pvname = "无",guid = 'null',pguid = "null",pvtype = 'area1',cvtype = "area1",CommonTreet;
var $,layer,form,table,tree,util,dtree;
layui.extend({
    dtree : '/js/layuiadmin-1.2.1/lib/extend/dtree-tp'
}).use(['table','form','layer','jquery','tree', 'util','dtree'], function () {
	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,tree = layui.tree,util = layui.util,dtree = layui.dtree;
	CommonTreet = dtree.render({
	    elem: "#dhtree",
	    data: getTree('/base/baseinfo/listtreejson'),
	});
	dtree.on("node('dhtree')" ,function(obj){
	    if(obj.parentParam.context){
	    	pvname = obj.parentParam.context,vname = obj.param.context;
	   	}else{
	   		pvname = '无',vname = obj.param.context;
	   	}
	    pguid = obj.param.parentId,guid = obj.param.nodeId;
	    var num = parseInt(obj.param.level)+1;
	    pvtype = 'area'+obj.param.level,cvtype = 'area'+num;
	    table.reload('dhtable', {url: "/base/baseinfo/list?pguid="+guid, where:{vname:'',bdeleted:''},page:{curr: 1}});
	});
	$.tablelist.init({
	    elem: '#dhtable'
	    ,url: "/base/baseinfo/list?vtype="+vtype
	    ,cols: [[
	        {type:'numbers', fixed: 'left'}
	        ,{field:'vname', title: '名称',align: 'center'}
	        //,{field:'bdefault', title: '是否默认项',align: 'center',templet: function(d){
	        //    return d.bdeleted?'是':'否'
	        //}}
	        ,{field:'iid', title: '排序值',align: 'center'}
	        ,{field:'vremark', title: '备注',align: 'center'}
	        ,{field:'bdeleted', title: '是否禁用',align: 'center',templet: function(d){
	                return d.bdeleted?'禁用':'启用'
	            }}
	        ,{field:'guid', title: 'ID',hide:true}
	        ,{fixed:'right', title: '操作',width:180,align: 'center', toolbar: '#barDemo'}
	    ]
	    ]
	    ,toolbar: '#toolbar1'
	    ,height:'full-' + ( $('.north').height()+20)
	})
	//搜索按钮
	$('#btn-search').on('click', function () {
		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
	      table.reload('dhtable', {page: {curr: 1},where:wherestr});
	   });
	//监听下拉框——添加条件
	form.on('select(fft)', function(obj){
		addMore(this);
	});
	//监听表格排序问题
	table.on('sort(ftable)', function (obj) {
	    $.tablelist.sort('ftable',obj);
	});
	//头工具栏事件
	table.on('toolbar(ftable)', function(obj){
	    switch(obj.event){
	        case 'addbtn':
	        	if(pguid=='null')pvname='无';
	            dialog('新增本级','/base/baseinfo/add?vtype='+pvtype+'&pguid='+pguid+'&pvname='+pvname+'&moduleTable=TB_baseinfo_area','500','460','addpost');
	            break;
	        case 'addchildbtn':
	            dialog('新增子级','/base/baseinfo/add?vtype='+cvtype+'&pguid='+guid+'&pvname='+vname+'&moduleTable=TB_baseinfo_area','500','460','addpost');
	            break;
	    };
	});
	//监听工具条
	table.on('tool(ftable)', function (obj) {
	    var data = obj.data;
	    if(obj.event === 'del'){ //删除
	        $.modal.confirmCom('确定要删除么？',function(){
	            $.operate.post('/base/baseinfo/deletepost',{'baseInfoItems':JSON.stringify([{'guid':data.guid}])},function(result){
	                allReload(result)
	            });
	        });
	    }else if (obj.event === 'edit') {
	        dialog('编辑','/base/baseinfo/edit?guid='+ data.guid+'&moduleTable=TB_baseinfo_area','500','430','editpost');
	    }
	});
	function dialog(title,url,width,height,Method){
	    $.modal.open(title,url,width,height,function(index){
	        var inputForm = $(window.frames["layui-layer-iframe" + index].document).contents().find(".layui-form");
	        var is_return = 0,
	            postStr = [],
	            must_field={},
	            Str = inputForm.serializeFormToJson();
	        $.each(k_fields,function (fk,fv) {
	            if(fv.fieldFrontRequired)
	                must_field[fk] = fv.fieldName + " 不能为空";
	        })
	        $.each(must_field,function (k,v) {
	            if(!inputForm.find("#"+k).val()){
	                layer.msg(v);
	                is_return = 1;
	                inputForm.find("#"+k).css('border','1px solid red');
	                inputForm.find("#"+k).focus()
	                return false;
	            }
	        })
	        if(is_return)return false;
	        if(!inputForm.find("#bdeleted").is(':checked')){Str['bdeleted'] = '1';}		//CheckBox 默认值0:启用,1:禁用 ;选中为0
	        postStr.push(Str);
	        var deldata = {'baseInfoItems':JSON.stringify(postStr)};
	        $.operate.post('/base/baseinfo/'+Method,deldata,function(result){
	            allReload(result)
	        });
	    })
	}
	function allReload(result){
	    if(result.code==0){
	        setTimeout(function(){
	            layer.closeAll();
	            table.reload('dhtable');
	            dtree.reload(CommonTreet,{
	                elem: "#dhtree",
	                data: getTree('/base/baseinfo/listtreejson'),
	                done: function(){
	                    var params = dtree.dataInit("dhtree", guid);
	                }
	            });
	        }, 1000);
	    }
	}
});
</script>
</body>
</html>